package com.qmx.launcher.adapter;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.open.androidtvwidget.leanback.adapter.GeneralAdapter;
import com.open.androidtvwidget.leanback.mode.OpenPresenter;
import com.qmx.launcher.QMXApplication;
import com.qmx.launcher.R;
import com.qmx.launcher.bean.ContactModel;
import com.qmx.launcher.utils.DateTimeUtils;

import de.hdodenhof.circleimageview.CircleImageView;
import io.realm.OrderedRealmCollection;

/**
 * @author ChengXiangtong
 * @create 2018/11/12
 * @Describe
 */
public class ContactMembersRecyclerViewPresenter extends OpenPresenter {

    private final OrderedRealmCollection<ContactModel> contactModels;
    private GeneralAdapter mAdapter;

    public ContactMembersRecyclerViewPresenter(OrderedRealmCollection<ContactModel> contactModels1) {
        this.contactModels = contactModels1;
    }

    @Override
    public void setAdapter(GeneralAdapter adapter) {
        this.mAdapter = adapter;
    }

    @Override
    public int getItemCount() {
        return contactModels.size();
    }

    @Override
    public int getItemViewType(int position) {
        return 0;
    }

    @Override
    public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_contact_group_members, parent, false);
        return new GridViewHolder(view);
    }

    @Override
    public void onBindViewHolder(ViewHolder viewHolder, int position) {
        GridViewHolder gridViewHolder = (GridViewHolder) viewHolder;
        CircleImageView imageview = gridViewHolder.imageview;
        TextView tv_contact_name = gridViewHolder.tv_contact_name;
        viewHolder.view.setTag(position);
        Glide.with(QMXApplication.getInstance()).load(contactModels.get(position).getName()).error(R.drawable.icon_group_contact).into(imageview);
        tv_contact_name.setText(contactModels.get(position).getName());
        System.err.println("onBindViewHolder===" + position);

    }

    public class GridViewHolder extends ViewHolder {

        public CircleImageView imageview;
        public TextView tv_contact_name;

        public GridViewHolder(View itemView) {
            super(itemView);
            imageview = (CircleImageView) itemView.findViewById(R.id.imageview);
            tv_contact_name = (TextView) itemView.findViewById(R.id.tv_contact_name);


        }

    }
}
